<?php
namespace app\index\controller;

class Lists extends Base
{
    public function index()
    {
    	$id = input('id',0,'intval');
    	$parentId = input('parentId',-1,'intval');
    	$order = input('order','');

    	$orders = [];
    	if(!empty($order)){
    		$orders[$order] = 'desc';
    	}
    	$orders['id'] = 'desc';


    	$condition[] = "end_time > ".(time()-100000000);
    	if($parentId == 0){
    		$condition[] = "category_id = ".$id;
    	}else if ($parentId > 0){
            $condition[] = "find_in_set(".$id.",se_category_id)";
    	}

    	$deals = model('deal')->where(implode(' AND ',$condition))->order($orders)->paginate();

    	// var_dump(model('deal')->getLastsql());die;
    	// var_dump($id.','.$parentId);die;
    	return $this->fetch('',[
    		'id' => $id,
    		'parentId' => $parentId,
    		'order' => $order,
    		'deals' => $deals,
    	]);
    	
    }
}
